//
//  HOMObjCValue.m
//  HigherOrderMessaging
//
//  Created by Ofri Wolfus on 11/28/05.
//  Copyright 2005 Ofri Wolfus. All rights reserved.
//

#import "HOMObjCValue.h"


@implementation HOMObjCValue

- (NSString *)description {
	//return [NSString stringWithFormat:@"<'%c' type %@: %p>", [self valueType], [self className], (void *)self];
	/*switch (value.type) {
		case NSObjCCharType:
			return [NSString stringWithFormat:@"< %@: %p { %c } >", [self className], self, [self charValue]];
			
		case NSObjCShortType:
			return [NSString stringWithFormat:@"< %@: %p { %hi } >", [self className], self, [self shortValue]];
			
		case NSObjCLongType:
			return [NSString stringWithFormat:@"< %@: %p { %d } >", [self className], self, [self longValue]];
			
		case NSObjCLonglongType:
			return [NSString stringWithFormat:@"< %@: %p { %qi } >", [self className], self, [self longlongValue]];
			
		case NSObjCFloatType:
			return [NSString stringWithFormat:@"< %@: %p { %f } >", [self className], self, [self floatValue]];
			
		case NSObjCDoubleType:
			return [NSString stringWithFormat:@"< %@: %p { %f } >", [self className], self, [self doubleValue]];
			
		case NSObjCBoolType:
			return [NSString stringWithFormat:@"< %@: %p { %u } >", [self className], self, [self boolValue]];
			
		case NSObjCSelectorType:
			return [NSString stringWithFormat:@"< %@: %p { %@ } >", [self className], self,
				NSStringFromSelector([self selectorValue])];
			
		case NSObjCStringType:
			return [NSString stringWithFormat:@"< %@: %p { %s } >", [self className], self, [self cStringLocation]];
			
		case NSObjCObjectType:
			return [NSString stringWithFormat:@"< %@: %p { %@ } >", [self className], self, [self objectValue]];
			
		case NSObjCStructType:
			return [NSString stringWithFormat:@"< %@: %p { %p } >", [self className], self, [self structLocation]];
			
		default:
			return [NSString stringWithFormat:@"< %@: %p { %p } >", [self className], self, [self pointerValue]];
	}*/
	NSMutableString *result = [NSMutableString stringWithFormat:@"< %@: %p { ", [self className], self];
	
	switch (value.type) {
		case NSObjCCharType:
			[result appendFormat:@"%c", [self charValue]];
			break;
			
		case NSObjCShortType:
			[result appendFormat:@"%hi", [self shortValue]];
			break;
			
		case NSObjCLongType:
			[result appendFormat:@"%d", [self longValue]];
			break;
			
		case NSObjCLonglongType:
			[result appendFormat:@"%qi", [self longlongValue]];
			break;
			
		case NSObjCFloatType:
			[result appendFormat:@"%f", [self floatValue]];
			break;
			
		case NSObjCDoubleType:
			[result appendFormat:@"%f", [self doubleValue]];
			break;
			
		case NSObjCBoolType:
			[result appendFormat:@"%u", [self boolValue]];
			break;
			
		case NSObjCSelectorType:
			[result appendFormat:@"%@", NSStringFromSelector([self selectorValue])];
			break;
			
		case NSObjCStringType:
			[result appendFormat:@"%s", [self cStringLocation]];
			break;
			
		case NSObjCObjectType:
			[result appendFormat:@"%@", [[self objectValue] description]];
			break;
			
		case NSObjCStructType:
			[result appendFormat:@"%p", [self structLocation]];
			break;
			
		default:
			[result appendFormat:@"%p", [self pointerValue]];
			break;
	}
	
	[result appendString:@" } >"];
	
	return result;
}

- (const char *)valueType {
	return (const char *)value.type;
}

- (char)charValue {
	return value.value.charValue;
}

- (BOOL)BOOLValue {
	return [self charValue];
}

- (short)shortValue {
	return value.value.shortValue;
}

- (long)longValue {
	return value.value.longValue;
}

- (long long)longlongValue {
	return value.value.longlongValue;
}

- (float)floatValue {
	return value.value.floatValue;
}

- (double)doubleValue {
	return value.value.doubleValue;
}

- (bool)boolValue {
	return value.value.selectorValue;
}

- (SEL)selectorValue {
	return value.value.selectorValue;
}

- (id)objectValue {
	return value.value.objectValue;
}

- (void *)pointerValue {
	return value.value.pointerValue;
}

- (void *)structLocation {
	return value.value.structLocation;
}

- (char *)cStringLocation {
	return value.value.cStringLocation;
}

- (int)intValue {
	return (int)value.value.longValue;
}

- (unsigned int)unsignedIntValue {
	return (unsigned int)value.value.longValue;
}

@end
